// TerminalMsgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dtdemo.h"
#include "DataFileDlg.h"
#include "Codelib.h"

// CDataFileDlg dialog

IMPLEMENT_DYNAMIC(CDataFileDlg, CDialog)

CDataFileDlg::CDataFileDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDataFileDlg::IDD, pParent)
	,m_pClient(NULL)
	,m_strDataFile(_T(""))
	, m_version(_T(""))
{

}

CDataFileDlg::~CDataFileDlg()
{
}

void CDataFileDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_DATAFILE, m_strDataFile);
	DDX_Text(pDX, IDC_EDIT1, m_version);
}


BEGIN_MESSAGE_MAP(CDataFileDlg, CDialog)
	ON_BN_CLICKED(IDC_SelectDataFile, &CDataFileDlg::OnBnClickedSelectDataFile)
	ON_BN_CLICKED(IDC_AddDataFile, &CDataFileDlg::OnBnClickedAdddatafile)
END_MESSAGE_MAP()


// CDataFileDlg message handlers
void CDataFileDlg::OnBnClickedSelectDataFile()
{
	// TODO: Add your control notification handler code here

	UpdateData(TRUE);
	CFileDialog dlg(TRUE);
	dlg.m_ofn.lpstrInitialDir = _T("C:\\");
	if(dlg.DoModal()==IDOK)
		m_strDataFile = dlg.GetPathName();
	UpdateData(FALSE);
}

void CDataFileDlg::OnBnClickedAdddatafile()
{
	// TODO: Add your control notification handler code here
	if(m_pClient != NULL)
	{
		UpdateData(TRUE);
		time_t now = time(NULL);
		char szBuff[16];
		memset(szBuff, 0, sizeof(szBuff));
		strftime(szBuff, sizeof(szBuff), "%Y%m%dT%H%M%S", localtime(&now));
		m_pClient->AddDataFile(CCodeLib::UnicodeToUTF8(m_strDataFile.GetString()), "12", "GSM", szBuff, szBuff, _wtoi(m_version.GetBuffer()));
	}
}
